<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
</head>
<body>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>设备信息维护 <small></small></h2>
                <ul class="nav navbar-right panel_toolbox">

                    <li> <button onclick="back()" class="btn btn-primary" type="button">返回</button>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <br>
                <div id="demo-form2"  class="form-horizontal form-label-left" >
                    <input type="hidden" name="id" class="form-data" >
                    <input type="hidden" name="companyId" class="form-data" >
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">名称
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="name" name="name"
                                   class="form-control form-data col-md-7 col-xs-12" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="companyId">企业
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="companyId" id="companyId" class="form-control form-data">
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="productId">监控产品类型
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="productId" id="productId" class="form-control form-data">
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="deveui">传感器编号
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="deveui" name="deveui"
                                   class="form-control form-data col-md-7 col-xs-12" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">描述
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea class="form-control form-data" name="desc" rows="3" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                            <button onclick="save()" class="btn btn-success">提交</button>
                            <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setTitle("基本信息>计量设备");
        buildSelect("/admin/mProduct/listAll.do","#productId","id","name",{});
        buildSelect("/admin/company/listAll.do","#companyId","id","name",{});
        initData();
    });

    function initData(){
        var data = getData();
        var id = data.id;
        if(null2empty(id) !==""){
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/device/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }
    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['name'])) {
            alert("请输入名称");
            return;
        }
        if (strIsNull(params['companyId'])) {
            alert("请输入选择企业");
            return;
        }
        if (strIsNull(params['productId'])) {
            alert("请选择产品");
            return;
        }
        if (strIsNull(params['deveui'])) {
            alert("请输入传感器编号");
            return;
        }
        $.ajax({
            url: "/admin/device/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goto("device_list.html");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function back() {

        goto("device_list.html");
    }
</script>
</html>